package shake.servlet;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.log4j.Logger;

import shake.filter.Filters;

import com.google.inject.Injector;

public class ShakeFilter implements javax.servlet.Filter {

	Logger logger = Logger.getLogger(ShakeFilter.class);

	public void destroy() {
		// Injector injector = ShakeServletContext.getInjector();
		// Filters filters = injector.getInstance(Filters.class);
		// filters.destroy();
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		Injector injector = ShakeServletContext.getInjector();
		Filters filters = injector.getInstance(Filters.class);
		filters.doFilter(request, response, chain);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		logger.info("start init");
		ShakeServletContext.setFilterConfig(filterConfig);
		Injector injector = ShakeServletContext.getInjector();
		Filters filters = injector.getInstance(Filters.class);
		filters.init();

	}

}
